﻿using System;
using System.IO;
using System.Text;
using SouthernLand.Common;

namespace SouthernLand.WebMaster
{
    public partial class KhachHang : BasePage
    {
        private string strFilePath;

        protected void Page_Load(object sender, EventArgs e)
        {
            lblTitle.Text = "Cập nhật nội dung trang khách hàng";

            strFilePath = Request.PhysicalApplicationPath + "UserUpload/Khachhang.txt";
            if (!Page.IsPostBack)
            {
                txtKhachHang.Text = ReadTextFile(strFilePath);
            }
        }

        public string ReadTextFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return "";
            }

            using (StreamReader sr = File.OpenText(filePath))
            {
                var text = new StringBuilder();
                String input;
                while ((input = sr.ReadLine()) != null)
                {
                    text.AppendLine(input);
                }
                sr.Close();
                return text.ToString();
            }
        }

        public void CreateTextFile(string filePath, string text)
        {
            using (StreamWriter sw = File.CreateText(filePath))
            {
                sw.WriteLine(text);
                sw.Close();
            }
        }

        protected void btSave_Click(object sender, EventArgs e)
        {
            CreateTextFile(strFilePath, txtKhachHang.Text);
        }
    }
}